//
//  MoreAdViewController.m
//  YTwallet
//
//  Created by ZhangLin on 2019/4/11.
//  Copyright © 2019年 hadrlog. All rights reserved.
//

#import "MoreAdViewController.h"
#import "HomeCollectionViewCell.h"
#import "HomeModelPack.h"
#import "UIImageView+WebCache.h"
#import "HomeWebViewController.h"
@interface MoreAdViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>
@property(nonatomic,strong)UICollectionView *financialServiceCollectionView;


@end

@implementation MoreAdViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    //创建collectonView
    [self setUpCollectionView];
    //创建lineView
    [self createLineView];
    self.title = @"更多";
}
-(void)createLineView
{
    UIView *lineView = [[UIView alloc] init];
    lineView.backgroundColor = ETTableViewLineColor;
    lineView.frame = CGRectMake(0, 0, ETScreenW, 1);
    [self.view addSubview:lineView];
}
-(void)setUpCollectionView
{
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    CGFloat with = (ETScreenW - 30) / 4.0;
    CGFloat higth = with;
    layout.itemSize = CGSizeMake(with,higth);
    layout.minimumLineSpacing = 5;
    layout.minimumInteritemSpacing = 5;
    layout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
    layout.scrollDirection = UICollectionViewScrollDirectionVertical;
    
    self.financialServiceCollectionView = [[UICollectionView alloc] initWithFrame:(CGRectMake(0, 10, ETScreenW, ETScreenH - 10 - 64)) collectionViewLayout:layout];
    [self.financialServiceCollectionView registerClass:[HomeCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    self.financialServiceCollectionView.backgroundColor = [UIColor whiteColor];
    self.financialServiceCollectionView.delegate = self;
    self.financialServiceCollectionView.dataSource = self;
    self.financialServiceCollectionView.alwaysBounceVertical = YES;
    [self.view addSubview:self.financialServiceCollectionView];
}

#pragma mark ---------------------------
#pragma mark -UICollectionView
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.recordArray.count;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    HomeCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
        HomeRecord *recoed = self.recordArray[indexPath.row];
        cell.titleLab.text = recoed.businessName;
        [cell.imageView sd_setImageWithURL:[NSURL URLWithString:recoed.imagePath] placeholderImage:[UIImage imageNamed:@"pos_icon_gift"]];
        cell.titleLab.text = recoed.businessName;
    return cell;
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *webViewPathStr = [self.recordArray[indexPath.row] pagePath];
    NSLog(@"%@",webViewPathStr);
    NSString *webViewTitleStr = [self.recordArray[indexPath.row] businessName];
    NSLog(@"%@",webViewTitleStr);
    HomeWebViewController *homeWebVC = [[HomeWebViewController alloc] init];
    homeWebVC.titleStr = webViewTitleStr;
    homeWebVC.urlStr = webViewPathStr;
    [self.navigationController pushViewController:homeWebVC animated:YES];
}

@end
